std::literals::string_literals:: operator""s
|
헤더 파일에 정의됨
<string>
|
||
|
std::
string
operator
""
s
(
const
char
*
str,
std::
size_t
len
)
;
|
(1) |
(C++14부터)
(C++20부터 constexpr) |
|
constexpr
std::
u8string
operator
""
s
(
const
char8_t
*
str,
std:: size_t len ) ; |
(2) | (C++20부터) |
|
std::
u16string
operator
""
s
(
const
char16_t
*
str,
std::
size_t
len
)
;
|
(3) |
(C++14부터)
(C++20부터 constexpr) |
|
std::
u32string
operator
""
s
(
const
char32_t
*
str,
std::
size_t
len
)
;
|
(4) |
(C++14부터)
(C++20부터 constexpr) |
|
std::
wstring
operator
""
s
(
const
wchar_t
*
str,
std::
size_t
len
)
;
|
(5) |
(C++14부터)
(C++20부터 constexpr) |
원하는 타입의 문자열 리터럴을 형성합니다.
목차 |
매개변수
| str | - | 원시 문자 배열 리터럴의 시작을 가리키는 포인터 |
| len | - | 원시 문자 배열 리터럴의 길이 |
반환값
문자열 리터럴.
참고 사항
이 연산자들은 네임스페이스
std
::
literals
::
string_literals
에 선언되어 있으며, 여기서
literals
와
string_literals
는 모두 인라인 네임스페이스입니다. 다음
using
지시문 중 하나를 사용하여 이러한 연산자에 접근할 수 있습니다:
- using namespace std :: literals
- using namespace std :: string_literals
- using namespace std :: literals :: string_literals
std::chrono::duration 는 리터럴 초를 나타내는 operator""s 도 정의하지만, 이는 산술 리터럴입니다: 10.0s 와 10s 는 10초를 나타내지만, "10" s 는 문자열입니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_string_udls
|
201304L
|
(C++14) | 문자열 타입을 위한 사용자 정의 리터럴 |
예제
#include <iostream> #include <string> void print_with_zeros(const auto note, const std::string& s) { std::cout << note; for (const char c : s) c ? std::cout << c : std::cout << "₀"; std::cout << " (size = " << s.size() << ")\n"; } int main() { using namespace std::string_literals; std::string s1 = "abc\0\0def"; std::string s2 = "abc\0\0def"s; print_with_zeros("s1: ", s1); print_with_zeros("s2: ", s2); std::cout << "abcdef"s.substr(1,4) << '\n'; }
출력:
s1: abc (size = 3) s2: abc₀₀def (size = 8) bcde
참고 항목
basic_string
을 생성합니다
(public member function) |
|
|
(C++17)
|
문자 배열 리터럴의 string view를 생성합니다
(function) |